import 'package:fbroadcast/fbroadcast.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

import '../../config/address.dart';
import '../../hj_model/splash/domain_source_model.dart';
import '../../hj_utils/screen.dart';
import '../../tools_base/event_bus/events.dart';
import '../../tools_base/global_store/store.dart';
import '../mine/vip_level_dialog.dart';

class VideoLineMenuAlert extends StatelessWidget {
  static show() async {
    return Get.bottomSheet(VideoLineMenuAlert());
    // return Get.dialog(VideoLineMenuAlert());
  }

  VideoLineMenuAlert();

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      mainAxisSize: MainAxisSize.min,
      children: [
        Material(
          color: Colors.transparent,
          child: Container(
            width: screen.screenWidth,
            padding: EdgeInsets.only(bottom: screen.paddingBottom),
            decoration: BoxDecoration(
              color: Color(0xff030F18),
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(20),
                topRight: Radius.circular(20),
              ),
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                18.sizeBoxH,
                SizedBox(
                  width: 36,
                  height: 5,
                  child: DecoratedBox(
                    decoration: BoxDecoration(
                      color: Colors.white.withOpacity(.2),
                      borderRadius: BorderRadius.circular(3),
                    ),
                  ),
                ),
                4.sizeBoxH,
                ..._buildLineArr(),
              ],
            ),
          ),
        ),
      ],
    );
  }

  List<Widget> _buildLineArr() {
    List<Widget> widgetArr = [];
    for (int i = 0; i < Address.cdnAddressLists.length; i++) {
      Domain domain = Address.cdnAddressLists[i];
      widgetArr.add(_buildContainItem(i, domain, domain.url == Address.cdnAddress));
    }
    return widgetArr;
  }

  Widget _buildContainItem(int index, Domain domain, bool isSelected) {
    return InkWell(
      onTap: () {
        if (!globalStore.isVIP()) {
          showVipLevelDialog("该线路仅限会员使用\n\n"
              "开通会员立享 极速观影体验");
        } else {
          Get.back();
          if (!isSelected) {
            Address.cdnAddress = Address.cdnAddressLists[index].url;
            FBroadcast.instance().broadcast(SWITCH_CDN_ADDRESS);
          }
        }
      },
      child: Container(
        height: 56,
        padding: EdgeInsets.fromLTRB(16, 0, 16, 0),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Expanded(
              child: Container(
                alignment: Alignment.center,
                child: Text(
                  domain.desc ?? "",
                  style: TextStyle(
                    fontSize: 14,
                    color: isSelected ? Color(0xffE1351F) : Colors.white.withOpacity(0.45),
                    fontWeight: isSelected ? FontWeight.w500 : FontWeight.w400,
                  ),
                ),
              ),
            ),
            Container(
              color: Colors.white.withOpacity(0.05),
              height: 1,
            ),
          ],
        ),
      ),
    );
  }
}
